package com.itheima.appserver.interceptor;

import com.itheima.commons.pojo.domain.User;

/**
 * @author yaohu
 * @date 2021/12/6
 * @Version 1.0
 * @describe
 */
public class UserThreadLocal {

    private static final ThreadLocal<User> threadLocal = new ThreadLocal<>();

    /**
     * 设置User到当前线程
     *
     * @param user
     */
    public static void set(User user) {
        threadLocal.set(user);
    }

    /**
     * 从当前线程获取User
     *
     * @return
     */
    public static User get() {
        return threadLocal.get();
    }

    /**
     * 从当前线程删除User
     */
    public static void remove() {
        threadLocal.remove();
    }

    /**
     * 获取User的id
     *
     * @return
     */
    public static Long getUserId() {
        return threadLocal.get().getId();
    }

    /**
     * 获取User的手机号
     *
     * @return
     */
    public static String getUserMobile() {
        return threadLocal.get().getMobile();
    }
}
